
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module http.pub
* @author: Hjava
* @description: HTTP模块的Pub相关接口
* @since: 2018-07-22 15:55:05
*/
var http_core_1 = __webpack_require__(/*! _http/http.core */ "./src/core/http/http.core.ts");
var constant_1 = __webpack_require__(/*! _util/constant */ "./src/core/utils/constant.ts");
var protocol_1 = __webpack_require__(/*! _util/protocol */ "./src/core/utils/protocol.ts");
var userData_1 = __webpack_require__(/*! _util/userData */ "./src/core/utils/userData.ts");
var log_1 = __webpack_require__(/*! ./../utils/log */ "./src/core/utils/log.ts");
var http_vcard_1 = __webpack_require__(/*! _http/http.vcard */ "./src/core/http/http.vcard.ts");
exports.default = {
    // 最近消息接口-拉取 PUB 会话列表,文档见:https://service.sankuai.com/#/services/com.sankuai.xm.xmnew.msgpubreader/docs/com.sankuai.xm.msg.read.pub.web.controller.MessageController_restful/com.sankuai.xm.msg.read.pub.web.controller.MessageController.getChatList(com.alibaba.fastjson.JSONObject%252C%2520javax.servlet.http.HttpServletRequest%252C%2520javax.servlet.http.HttpServletResponse)
    chatlistByTime: function (options) {
        http_core_1.default._pubChatlist('/msg/api/pub/v1/chatlist', options);
    },
    chatListByAppId: function (options) {
        http_core_1.default._pubChatlist('/pubread/v2/user/chat/getPubList/byAppId', options);
    },
    // 离线消息
    offline: function (options) {
        options.data.svid = 410;
        http_core_1.default._offline('/msg/api/pub/v1/offline/chat', options, constant_1.LOG_FROM_SOURCE.PUB);
    },
    // pub 消息接口
    historyOfChannelByRange: function (options) {
        options.data.svid = 410;
        http_core_1.default._history('/msg/api/pub/v3/history/chat/range', options, constant_1.LOG_FROM_SOURCE.PUB);
    },
    historyReverseOfChannelByRange: function (options) {
        options.data.svid = 410;
        http_core_1.default._history('/msg/api/pub/v3/history/chat/reverse/range', options, constant_1.LOG_FROM_SOURCE.PUB);
    },
    // 大象 Web 滚动列表使用:https://service.sankuai.com/#/services/com.sankuai.xm.xmnew.msgpubreader/docs/com.sankuai.xm.msg.read.pub.web.controller.MessageController_restful/com.sankuai.xm.msg.read.pub.web.controller.MessageController.getChatHistoryReverseById(com.alibaba.fastjson.JSONObject%252C%2520javax.servlet.http.HttpServletRequest%252C%2520javax.servlet.http.HttpServletResponse)
    historyReverseById: function (options) {
        options.data.svid = 410;
        http_core_1.default._history('/msg/api/pub/v1/history/chat/reverse/byid', options, constant_1.LOG_FROM_SOURCE.PUB);
    },
    /**
     * 获取单条消息
     * @param read {}
     */
    single: function (options) {
        options.data.svid = 410;
        http_core_1.default._history('/msg/api/pub/v1/single', options, constant_1.LOG_FROM_SOURCE.PUB);
    },
    /**
     * 获取unread
     * @param read {}
     */
    _unreads: function (url, options) {
        var _suc = options.success;
        options.success = function (res) {
            if (res.rescode === 0) {
                res.data['sync_data'] = protocol_1.default.Response.fromBase64(res.data['sync_data']);
                res.data['sync_data2'] && (res.data['sync_data2'] = protocol_1.default.Response.fromBase64(res.data['sync_data2'], 2));
            }
            _suc(res);
        };
        http_core_1.default.request(url, options);
    },
    /**
     * 发送Read
     * @param read {}
     */
    readSync: function (options) {
        options.data.req = options.data.req.getBase64();
        http_core_1.default.request('/pubread/v1/user/chat/sync', options);
    },
    /**
     * 获取PUB端已读时间
     * @param read {}
     */
    unreads: function (options) {
        this._unreads('/pubread/v2/user/chat/getUnread', options);
    },
    getPubUnreadList: function (options) {
        this._unreads('/v2/user/chat/getUnread', options);
    },
    /**
     * PUB获取会话上一条非强制撤回消息
     * @param {id: 当前收到的强制撤回的消息mid, ps: {u: Pub会话pubId}}
     */
    getPreviousMessage: function (options) {
        var _suc = options.success;
        options.data.u = userData_1.default.get('uid');
        options.data.ai = userData_1.default.get('appId');
        options.data.svid = 410;
        options.success = function (res) {
            var data = res.data['res'];
            if (res.rescode === 0) {
                for (var i = 0; i < data.length; i++) {
                    try {
                        data[i] = protocol_1.default.Response.fromBase64(data[i]);
                    }
                    catch (e) {
                        if (i > 0) {
                            log_1.default.error('~~~~~ : topChatlist解析失败，上一条记录');
                            log_1.default.error(protocol_1.default.Response.fromBase64(data[i - 1]));
                        }
                        log_1.default.error('~~~~~topChatlist 解析失败，当前原始数据 info:' + e);
                        log_1.default.error(data[i]);
                    }
                }
            }
            _suc(res);
        };
        http_core_1.default.request('/msg/api/pub/v3/message/previous', options);
    },
    getPubVcard: function (options) {
        http_vcard_1.default.getPubVcard(options);
    },
    getOppositeConfig: function (_a) {
        var success = _a.success, fail = _a.fail;
        var options = {
            data: {
                appId: userData_1.default.get('appId'),
                svid: 410
            },
            success: success,
            fail: fail
        };
        http_core_1.default.request('/pubread/v1/user/chat/config/tenant/opposite', options);
    },
    getOppositeReadTime: function (_a) {
        var _b = _a.data, _c = _b.channelId, channelId = _c === void 0 ? 0 : _c, _d = _b.chatIds, chatIds = _d === void 0 ? [] : _d, startTime = _b.startTime, sid = _b.sid, _e = _a.success, success = _e === void 0 ? function () {
            // do nothing
        } : _e, _f = _a.fail, fail = _f === void 0 ? function () {
            // do nothing
        } : _f;
        var options = {
            data: __assign({ svid: 410, channel: channelId, chatIds: chatIds,
                startTime: startTime }, (sid ? { sid: sid } : {})),
            success: success,
            fail: fail
        };
        http_core_1.default.request('/pubread/v1/user/chat/opposite/getReadList', options);
    },
    getMessageAdditionConfig: function (options) {
        http_core_1.default.request('/msg/api/pub/v1/addition/config', options);
    },
    getPubMessageAddition: function (options) {
        http_core_1.default._messageAddition('/msg/api/pub/v1/addition/query', options, constant_1.LOG_FROM_SOURCE.PUB);
    },
    getChatlistInfo: function (options) {
        http_core_1.default.request('/msg/api/pub/v1/chatlist/info', options);
    }
};


//# sourceURL=webpack://MTDX/./src/core/http/http.pub.ts?